﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 设计模式.Adapter
{
    /// <summary>
    /// 公开功能
    /// </summary>
    public class AdapterFun
    {
        public void TestAdapter(IStandard standard)
        {
            standard.ResponseDo();
        }
        public void TestAdapter(Action standard)
        {
            new TargetFun(standard).ResponseDo();
        }
    }

    /// <summary>
    /// 接口标准
    /// </summary>
    interface IStandard
    {
        void ResponseDo();
    }
    /// <summary>
    /// 标准实现
    /// </summary>
    class Target : IStandard
    {
        public void ResponseDo()
        {
            Console.WriteLine("标准实现");
        }
    }

    /// <summary>
    /// 委托适配器-特殊的业务
    /// </summary>
    class TargetFun : IStandard
    {
        private readonly Action _eventHandlerDelegate;
        public TargetFun(Action eventHandlerDelegate)
        {
            this._eventHandlerDelegate = eventHandlerDelegate;
        }

        public void ResponseDo()
        {
            this._eventHandlerDelegate();
        }
    }

}
